
//week weather
let cityCode = localStorage.getItem('cityCode') || '370300'

function getWeather(cityCode) {
    axios({
        url: 'https://hmajax.itheima.net/api/weather'
        , params: {
            city: cityCode
        }
    }).then(res => {
        // console.log(res);
        // console.log(res.data.data);


        const dateForecast = res.data.data.dayForecast
        // console.log(dateForecast);
        const dateForecastHTML = dateForecast.map(item => {
            return `
        <li class="item">
                    <div class="date-box">
                        <span class="dateFormat">${item.dateFormat}</span>
                        <span class="date">${item.date}</span>
                    </div>
                    <img src="${item.weatherImg}" alt="" class="weatherImg">
                    <span class="weather">${item.weather}</span>
                    <div class="temp">
                        <span class="temNight">${item.temDay}</span>-
                        <span class="temDay">${item.temNight}</span>
                        <span>℃</span>
                    </div>
                    <div class="wind">
                        <span class="windDirection">${item.windDirection}</span>
                        <span class="windPower">${item.windPower}</span>
                    </div>
                </li>
    `
        }).join('')
        document.querySelector('.week-wrap').innerHTML = dateForecastHTML
    }).catch(err => {
        console.dir(err);
    })
}


getWeather(cityCode);